package top.api.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import top.api.common.ResUlt;
import top.api.domain.dto.PageDto;
import top.api.domain.pojo.User;
import top.api.service.UserService;

import java.util.List;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@Api(tags = "用户管理")
public class UserController {
    private final UserService userService;


    @GetMapping("/list")
//    @SaCheckRole("admin")
    @ApiOperation("分页查询")
    public ResUlt<?> listPage(PageDto pageDto,Integer id,String username){
        return userService.listPage(pageDto,id,username);
    }


    @PostMapping("/adduser")
    @SaCheckRole("admin")
    @ApiOperation("分页查询")
    public ResUlt<?> add(@RequestBody User user){
        return userService.add(user);
    }


    @GetMapping("{id}")
    @ApiOperation("获取用户信息")
    public ResUlt<?> getOne(@PathVariable Integer id){
        return userService.getOne(id);
    }

    @DeleteMapping("{id}")
    @SaCheckRole("admin")
    @ApiOperation("删除用户信息")
    public ResUlt<?> delete(@PathVariable List id){
        return userService.delete(id);
    }

    @PutMapping("/upUser")
    @SaCheckRole("admin")
    @ApiOperation("更新用户信息")
    public ResUlt<?> updateUser(@RequestBody User user){
        return userService.changeUser(user);
    }

    @PutMapping("/status")
    @SaCheckRole("admin")
    @ApiOperation("封禁用户账号")
    public ResUlt<?> changeStatus(@RequestBody User user){
        return userService.changeStatus(user);
    }
}
